www.gusucode.com > VC++ 实现多幅图像的打印-源码程序 > VC++ 实现多幅图像的打印-源码程序/code/print/printDoc.cpp
//Download by http://www.NewXing.com // printDoc.cpp : implementation of the CPrintDoc class // #include "stdafx.h" #include "print.h" #include "printDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPrintDoc IMPLEMENT_DYNCREATE(CPrintDoc, CDocument) BEGIN_MESSAGE_MAP(CPrintDoc, CDocument) //{{AFX_MSG_MAP(CPrintDoc) ON_COMMAND(ID_FILE_ADD, OnFileAdd) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPrintDoc construction/destruction CPrintDoc::CPrintDoc() { // TODO: add one-time construction code here for(int i=0;i<6;i++) m_string[i]=""; pPic=NULL; pStm=NULL; m_flag=0; pPic_add1=NULL; pPic_add2=NULL; pPic_add3=NULL; pPic_add4=NULL; pPic_add5=NULL; } CPrintDoc::~CPrintDoc() { if(pPic_add5!=NULL) pPic_add5->Release(); if(pPic_add4!=NULL) pPic_add4->Release(); if(pPic_add3!=NULL) pPic_add3->Release(); if(pPic_add2!=NULL) pPic_add2->Release(); if(pPic_add1!=NULL) pPic_add1->Release(); if(pPic!=NULL) pPic->Release(); if(pStm!=NULL) pStm->Release(); } BOOL CPrintDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CPrintDoc serialization void CPrintDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CPrintDoc diagnostics #ifdef _DEBUG void CPrintDoc::AssertValid() const { CDocument::AssertValid(); } void CPrintDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPrintDoc commands BOOL CPrintDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; // TODO: Add your specialized creation code here CFile file; if (file.Open(lpszPathName,CFile::modeRead) &&file.GetStatus(lpszPathName, fstatus) && ((cb = fstatus.m_size) != -1)) { HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb); LPVOID pvData = NULL; if (hGlobal != NULL) { if ((pvData = GlobalLock(hGlobal)) != NULL) { file.ReadHuge(pvData, cb); GlobalUnlock(hGlobal); CreateStreamOnHGlobal(hGlobal, TRUE, &pStm); ASSERT(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size, TRUE,IID_IPicture,(LPVOID*)&pPic))); m_flag=1; } } } return TRUE; } void CPrintDoc::OnFileAdd() { // TODO: Add your command handler code here char szFileters[]="JPEG files(*.JPG;*.JPEG;*.JPE;*.JFIF)|*.JPG;*.JPEG;*.JPE;*.JFIF||"; CFileDialog opendlg(TRUE,"","",OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,szFileters,NULL); if(opendlg.DoModal()==IDOK) { if(opendlg.GetFileExt()=="jpg"|opendlg.GetFileExt()=="jpeg" |opendlg.GetFileExt()=="jpe"|opendlg.GetFileExt()=="JPG" |opendlg.GetFileExt()=="JPEG"|opendlg.GetFileExt()=="JPE") { CFile file; if (file.Open(opendlg.GetPathName(),CFile::modeRead) &&file.GetStatus(opendlg.GetPathName(), fstatus) && ((cb = fstatus.m_size) != -1)) { HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb); LPVOID pvData = NULL; if (hGlobal != NULL) { if ((pvData = GlobalLock(hGlobal)) != NULL) { file.ReadHuge(pvData, cb); GlobalUnlock(hGlobal); CreateStreamOnHGlobal(hGlobal, TRUE, &pStm); if(m_flag==0) ASSERT(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size, TRUE,IID_IPicture,(LPVOID*)&pPic))); else if(m_flag==1) ASSERT(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size, TRUE,IID_IPicture,(LPVOID*)&pPic_add1))); else if(m_flag==2) ASSERT(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size, TRUE,IID_IPicture,(LPVOID*)&pPic_add2))); else if(m_flag==3) ASSERT(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size, TRUE,IID_IPicture,(LPVOID*)&pPic_add3))); else if(m_flag==4) ASSERT(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size, TRUE,IID_IPicture,(LPVOID*)&pPic_add4))); else if(m_flag==5) ASSERT(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size, TRUE,IID_IPicture,(LPVOID*)&pPic_add5))); if(m_flag<6) { m_flag+=1; UpdateAllViews(NULL); } else AfxMessageBox("已满6幅图像!"); } } } } } }